package com.tc.juc.design;

import lombok.extern.slf4j.Slf4j;

/**
 * @Auther: tianchao
 * @Date: 2021/10/4 18:54
 * @Description:
 */
@Slf4j
public class TestOrderWaitNotify {
    static final Object lock = new Object();
    static boolean t2Run = false;
    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            synchronized (lock){
                while (!t2Run){
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                log.info("1");
            }
        },"t1");
        Thread t2 = new Thread(()->{
            synchronized (lock){
                log.info("2");
                t2Run = true;
                lock.notifyAll();
            }
        },"t2");
        t1.start();
        t2.start();
    }
}
